package com.mycompany.myapp.web.rest.electricbicyclecontroller;

import com.codahale.metrics.annotation.Timed;
import com.mycompany.myapp.domain.ElecBicycleUser;
import com.mycompany.myapp.repository.ElecBicycleUserRepository;
import com.mycompany.myapp.service.ElecBicycleUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * Create by wys on 2018/7/25
 */

@RestController
@RequestMapping("/api")
@Api(tags = "电动车用户相关API")
public class ElecBicycleUserController {

    @Autowired
    ElecBicycleUserService elecBicycleUserService;

    @Autowired
    ElecBicycleUserRepository elecBicycleUserRepository;

    Logger log = LoggerFactory.getLogger(ElecBicycleUserController.class);

    @PostMapping("/borrowElecBicycle")
    @ApiOperation(value = "用户借车",notes = "用户借车")
    @ApiParam(value = "用户手机号码")
    @Timed
    public ResponseEntity<String> borrowElecBicycle(@RequestParam String phoneNumber) {

        String result = "";


        result = elecBicycleUserService.borrowElecBicycle(phoneNumber);

        return ResponseEntity.ok()
            .body(result);
    }

    @PostMapping("/returnElecBicycle")
    @ApiOperation(value = "用户还车",notes = "用户还车")
    @Timed
    public ResponseEntity<String> returnElecBicycle(@RequestParam String phoneNumber) {

        String result = "";

        result = elecBicycleUserService.returnElecBicycle(phoneNumber);

        return ResponseEntity.ok()
            .body(result);
    }

    @GetMapping("/getOne")
    @ApiOperation(value = "获得一个用户")
    @Timed
    public ResponseEntity<ElecBicycleUser> getOne(@RequestParam String phoneNumber) {

        elecBicycleUserRepository.findAll();

        ElecBicycleUser elecBicycleUser = elecBicycleUserRepository
            .findElecBicycleUserByPhoneNumber(phoneNumber);

        return ResponseEntity.ok()
            .body(elecBicycleUser);

    }



}
